package com.theBlind.orm;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

/**
 * @program: orm
 * @description:
 * @author: TheBlind
 * @create: 2021-04-22 14:48
 **/
public class DefaultSqlSession implements SqlSession {

    private Connection connection;
    private Executor executor;
    private Map<String , MapperStatement> mapperElement;


    public DefaultSqlSession(Connection connection, Map<String, MapperStatement> mapperElement,Executor executor) {
        this.connection = connection;
        this.mapperElement = mapperElement;
        this.executor=executor;
    }

    @Override
    public <T> T selectOne(String statement) {

        MapperStatement mapperStatement = mapperElement.get(statement);
        try {
            PreparedStatement preparedStatement = connection.prepareStatement(mapperStatement.getSql());

            ResultSet resultSet = preparedStatement.executeQuery();


        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return null;
    }

    @Override
    public <T> T selectOne(String v1, Object v2) {
        return null;
    }

    @Override
    public <E> List<E> selectList(String statement) {
        MapperStatement mapperStatement = mapperElement.get(statement);
        try {
            PreparedStatement preparedStatement = connection.prepareStatement(mapperStatement.getSql());
            ResultSet resultSet = preparedStatement.executeQuery();

        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

        return null;
    }

    @Override
    public <E> List<E> selectList(String v1, Object v2) {
        return null;
    }


    @Override
    public void close() throws IOException {

    }






}
